package com.xmsit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmsit.pojo.AdsConsumeStatDay;
import com.xmsit.pojo.AdsConsumeStatLastMonth;
import com.xmsit.service.AdsConsumeStatDayService;
import com.xmsit.mapper.AdsConsumeStatDayMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;

/**
* @author 徐
* @description 针对表【ads_consume_stat_day(能耗主题日统计表)】的数据库操作Service实现
* @createDate 2025-05-15 19:18:32
*/
@Service
public class AdsConsumeStatDayServiceImpl extends ServiceImpl<AdsConsumeStatDayMapper, AdsConsumeStatDay>
    implements AdsConsumeStatDayService{

    @Override
    public List<AdsConsumeStatDay> getAdsConsumeStatDay(String vin) {
        LambdaQueryWrapper<AdsConsumeStatDay> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdsConsumeStatDay::getVin, vin);
        LocalDate now = LocalDate.now();
        LocalDate localDate1 = now.minusDays(1);
        LocalDate localDate2 = now.minusWeeks(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String endDay = localDate1.format(formatter);
        String staDay = localDate2.format(formatter);
        queryWrapper.ge(AdsConsumeStatDay::getDay, staDay);
        queryWrapper.le(AdsConsumeStatDay::getDay, endDay);
        List<AdsConsumeStatDay> adsConsumeStatDays = list(queryWrapper);
        return adsConsumeStatDays;
    }
}




